package com.gc.tpas.controller;

import com.gc.tpas.entity.QaUser;
import com.gc.tpas.service.QaInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2018/5/2 0002.
 */
@Controller
public class MainController {

    @Autowired
    QaInfoService qaInfoService;

    @RequestMapping("/main")
    public String main(Model model){
        model.addAttribute("qalist",qaInfoService.getAllQa());
        return "main";
    }
    @RequestMapping("/index")
    public String index(){
        return "login";
    }
    @RequestMapping("/edit")
    public String edit(){
        return "detail";
    }

    @RequestMapping("/add")
    public String add(Model model){
        model.addAttribute("typelist",qaInfoService.getTypes());
        return "add";
    }
    @RequestMapping("/myinfo")
    public String myinfo(Model model,HttpSession session){
        QaUser user = (QaUser) session.getAttribute("user");
        model.addAttribute("myqa",qaInfoService.getMyQainfo(user));
        model.addAttribute("mypartakeqa",qaInfoService.getMyPartakeQainfo(user));
        model.addAttribute("mysolveqa",qaInfoService.getMySolveQainfo(user));
        return "myinfo";
    }
}
